package demo7;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class Person {
    private String name;
    public Person(){
        System.out.println("1:Person的构造器被调用了");
    }

    public String getName() {
        return name;
    }

    @Value("张三")
    public void setName(String name) {
        System.out.println("2:name的set方法被调用了，初始化了name属性");
        this.name = name;
    }
    public void play(){
        System.out.println(name+"出去玩");
    }
    @PostConstruct
    public void init(){
        System.out.println("3:Spring容器将Person对象初始化完毕了，name:"+name);
    }
    @PreDestroy
    public void perDestory(){
        System.out.println("5:Spring容器要关闭了，通知当前对象");
    }

    public void finalize(){}
}
